<%@ page language="java" import="java.util.*,com.mag.domain.*" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>供货商信息</title>
    <SCRIPT language="javascript" type="text/javascript"></SCRIPT>
    <style type="text/css" media="screen">
        .center {
            margin: 8%;
            text-align: center;
        }
    </style>
    <SCRIPT language="javascript" type="text/javascript">
        function calculateRates() {
            var NumFault = parseFloat(document.getElementsByName("NumFault")[0].value);
            var AccumulativeLevel = parseFloat(document.getElementsByName("AccumulativeLevel")[0].value);
            var NumBacklogging = parseFloat(document.getElementsByName("NumBacklogging")[0].value);
            var AccumulativeTime = parseFloat(document.getElementsByName("AccumulativeTime")[0].value);

            var NoFaultRate = 1 - (NumFault / AccumulativeLevel);
            var DeliveryOnTime = 1 - (NumBacklogging / AccumulativeTime);

            document.getElementsByName("NoFaultRate")[0].value = NoFaultRate.toFixed(2);
            document.getElementsByName("DeliveryOnTime")[0].value = DeliveryOnTime.toFixed(2);
        }

        function validate_form_update(form) {
            var fields = ["SupplierName", "SupplierAddress", "WebSite", "SupplierPhone",
                "FaxSupplier", "OfficialEmail", "PersonContact", "PhoneContact",
                "DateBulid", "GoodsSupply", "DateFirstSupply", "AccumulativeTime",
                "AccumulativeLevel", "NumFault", "NumBacklogging", "TotalMoney",
                "NoFaultRate", "DeliveryOnTime"];

            for (var i = 0; i < fields.length; i++) {
                var txt = form.elements[fields[i]];
                if (txt.value == null || txt.value == "") {
                    alert("请填写" + fields[i] + "！");
                    txt.focus();
                    return false;
                }
            }

            var integerFields = ["AccumulativeTime", "AccumulativeLevel", "NumFault", "NumBacklogging"];
            for (var j = 0; j < integerFields.length; j++) {
                var field = integerFields[j];
                if (!Number.isInteger(Number(form.elements[field].value))) {
                    alert(integerFields[j] + "应为整数！");
                    form.elements[field].focus();
                    return false;
                }
            }

            var doubleFields = ["TotalMoney"];
            for (var j = 0; j < doubleFields.length; j++) {
                var field = doubleFields[j];
                if (isNaN(parseFloat(form.elements[field].value))) {
                    alert(doubleFields[j] + "应填写数字！");
                    form.elements[field].focus();
                    return false;
                }
            }

            var dateFormat = /^\d{4}-\d{2}-\d{2}$/;
            if (!dateFormat.test(form.elements["DateBulid"].value)) {
                alert("关系建立时间格式应为YYYY-MM-DD！");
                form.elements["DateBulid"].focus();
                return false;
            }
            if (!dateFormat.test(form.elements["DateFirstSupply"].value)) {
                alert("首次供货时间格式应为YYYY-MM-DD！");
                form.elements["DateFirstSupply"].focus();
                return false;
            }

            return true;
        }

        function submitForm(form) {
            if (validate_form_update(form)) {
                alert("提交成功！");
                return true;
            }
            return false;
        }
    </SCRIPT>
</head>

<body onload="load()" style="background-color: #D9ECF6;">
<div class="center">
    <img src="/manager/img/logo.jpg" style="position: absolute; top: 0; right: 0; width: 160px; height: 160px;">
    <form action="/manager/Suppliersu?type=Update&supplierid=${ updateSupplier.supplierID }"
          onsubmit="return submitForm(this)" method="post">
        <table border="0" style="MARGIN-RIGHT: auto; MARGIN-LEFT: auto; width:600px;font-size: 22px;">
            <tr align="center">
                <td colspan=2><h1>供货商信息</h1></td>
            </tr>
            <%
                Suppliers supplier = new Suppliers();
                supplier = (Suppliers) request.getSession().getAttribute("updateSupplier");
            %>
            <tr align="center">
                <td>供货商ID：</td>
                <td>${ updateSupplier.supplierID }</td>
            </tr>
            <tr align="center">
                <td>名称：</td>
                <td><input type="text" name="SupplierName" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getSupplierName() %>"/></td>
            </tr>
            <tr align="center">
                <td>通信地址：</td>
                <td><input type="text" name="SupplierAddress" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getSupplierAddress() %>"/></td>
            </tr>
            <tr align="center">
                <td>网址：</td>
                <td><input type="text" name="WebSite" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getWebSite() %>"/></td>
            </tr>
            <tr align="center">
                <td>公司电话：</td>
                <td><input type="text" name="SupplierPhone" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getSupplierPhone() %>"/></td>
            </tr>
            <tr align="center">
                <td>公司传真：</td>
                <td><input type="text" name="FaxSupplier" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getFaxSupplier()+"" %>"/></td>
            </tr>
            <tr align="center">
                <td>公务邮箱：</td>
                <td><input type="text" name="OfficialEmail" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getOfficialEmail()+"" %>"/></td>
            </tr>
            <tr align="center">
                <td>联系人：</td>
                <td><input type="text" name="PersonContact" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getPersonContact()+"" %>"/></td>
            </tr>
            <tr align="center">
                <td>联系人电话：</td>
                <td><input type="text" name="PhoneContact" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getPhoneContact() %>"/></td>
            </tr>
            <tr align="center">
                <td>关系建立时间：</td>
                <td><input type="text" name="DateBulid" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getDateBulid() %>"/></td>
            </tr>
            <tr align="center">
                <td>供应物品：</td>
                <td><input type="text" name="GoodsSupply" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getGoodsSupply() %>"/></td>
            </tr>
            <tr align="center">
                <td>首次供货时间：</td>
                <td><input type="text" name="DateFirstSupply" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%= supplier.getDateFirstSupply() %>"/></td>
            </tr>
            <tr align="center">
                <td>累计供货次数：</td>
                <td><input type="text" name="AccumulativeTime" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getAccumulativeTime() %>" oninput="calculateRates()"/></td>
            </tr>
            <tr align="center">
                <td>累计供货量：</td>
                <td><input type="text" name="AccumulativeLevel" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getAccumulativeLevel() %>" oninput="calculateRates()"/></td>
            </tr>
            <tr align="center">
                <td>累计次品数：</td>
                <td><input type="text" name="NumFault" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getNumFault() %>" oninput="calculateRates()"/></td>
            </tr>
            <tr align="center">
                <td>延期交货次数：</td>
                <td><input type="text" name="NumBacklogging" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getNumBacklogging() %>" oninput="calculateRates()"/></td>
            </tr>
            <tr align="center">
                <td>累计供货金额：</td>
                <td><input type="text" name="TotalMoney" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getTotalMoney() %>"/></td>
            </tr>
            <tr align="center">
                <td>无次品率：</td>
                <td><input type="text" name="NoFaultRate" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getNoFaultRate() %>"/></td>
            </tr>
            <tr align="center">
                <td>按时交货率：</td>
                <td><input type="text" name="DeliveryOnTime" style="width: 400px;height: 30px;font-size: 22px;"
                           value="<%=supplier.getDeliveryOnTime() %>"/></td>
            </tr>
            <tr align="center">
                <td colspan=2><input type="submit" style="width:70px;height:30px; font-size:20px;" id="saveInfo"
                                     value="提交"/>
                    <input type="button" style="width:70px;height:30px;font-size:20px;" value="返回"
                           onclick="window.location.href='/manager/SearchSupplier?type=allsupplier'">
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>